package agents;

import extra.Position;
import game.constants.ReferenceAgent;
import game.constants.ReferenceSpecialFeature;
import interfaces.impl.Agent;
import objects.SpetialFeature;
import objects.WorldObject;
import universe.Universe;
import actions.ActionReciveAttack;
import constants.Constants;



public class AgentAttack extends Agent{
	
	SpetialFeature targetToAttack;
	SpetialFeature timeToAttack;
	SpetialFeature damage;
	SpetialFeature attackRange;
	
	ActionReciveAttack actionReciveAttack = new ActionReciveAttack();
	
	double contTime=0;
	@Override
	public void initializeActionList() {
		// 
		
	}

	@Override
	public void initializeSpecialFeatures() {
		targetToAttack= new SpetialFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_TARGET_ID_TO_ATTACK);
		listFeatures.add(targetToAttack);
		
		timeToAttack = new SpetialFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_ATTACK_TIME);
		listFeatures.add(timeToAttack);
		
		damage= new SpetialFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_DAMAGE);
		listFeatures.add(damage);
		
		attackRange= new SpetialFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_ATTACK_RANGE);
		listFeatures.add(attackRange);
	}

	@Override
	public void initializeName() {
		name="Agent Attack";
		
	}

	@Override
	public void initializeId() {
		this.id=ReferenceAgent.AGENT_ATTACK;
		
	}

	@Override
	public void updateChild(WorldObject object, Universe universe, double time) {
		
		if(targetToAttack.getValue()==Constants.NO_OBJECT_ID){
			return;
		}
		//System.out.println("Update del attack1");
		WorldObject objToAttack = universe.getObject((int)targetToAttack.getValue());
		
		if(objToAttack==null){
			return;
		}
		//System.out.println("Update del attack2");
		double distance = Position.DistanceBetween(objToAttack.getPosition(),object.getPosition());
		if(distance>attackRange.getValue()){
			
			System.out.println("NO LO VEO Para atacarlo");
			return;
		}
		//System.out.println("Update del attack3");
		contTime=contTime+time;
		if(contTime>timeToAttack.getValue()){
			
			//System.out.println("Update del attack4");
			actionReciveAttack= new ActionReciveAttack();
			actionReciveAttack.setDamage(damage.getValue());
			actionReciveAttack.setSource(object);
			actionReciveAttack.setTarget(objToAttack);
			universe.setAction(actionReciveAttack);
			
			contTime=0;
		}
		
	}

	
	
	

}
